<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
    <script src="/webjars/jquery/3.4.1/jquery.js" type="text/javascript"></script>
    <script src="/webjars/bootstrap/3.3.7/js/bootstrap.js" type="text/javascript"></script>
    <script src="/webjars/vue/2.6.10/dist/vue.js" type="text/javascript"></script>
    <script src="/webjars/axios/0.19.0/dist/axios.js" type="text/javascript"></script>
</head>
<body>
  <div id="vuebox">
      <div class="container" style="margin-top: 50px">
          <h1 class="text-center">房屋信息表查询</h1>
          <a href="#" @click.prevent="addHouse">发布房源</a>
          <table style="margin-top: 20px" class="table table-striped">
              <thead>
              <tr>
                  <th>序号</th>
                  <th>描述</th>
                  <th>户型</th>
                  <th>租金</th>
                  <th>发布时间</th>
              </tr>
              </thead>
              <tbody>
              <tr v-for="item in entries.data.list">
                  <td>{{item.houseid}}</td>
                  <td>{{item.housedesc}}</td>
                  <td>
                      <p v-if="item.typeid==1">一室一厅</p>
                      <p v-if="item.typeid==2">二室一厅</p>
                      <p v-if="item.typeid==3">叁室一厅</p>
                  </td>
                  <td>{{item.monthrent}}元/月</td>
                  <td>{{item.publishdate}}</td>

              </tr>
              </tbody>
          </table>
          <br/>
          <div class="text-center">
              <ul class="pagination">
                  <li v-show="entries.data.hasPreviousPage">
                      <a href="#" @click.stop="selectEntry(entries.data.prePage)">&laquo;</a>
                  </li>
                  <li v-for="i in entries.data.navigatepageNums" :class="{active:entries.data.pageNum==i}">
                      <a href="#" @click.stop="selectEntry(i)">{{i}}</a>
                  </li>
                  <li v-show="entries.data.hasNextPage">
                      <a href="#" @click.stop="selectEntry(entries.data.nextPage)">&raquo;</a>
                  </li>
              </ul>
          </div>
      </div>

      <!--模态框-->
      <div class="modal" id="mymodal">
          <div class="modal-dialog">
              <div class="modal-content">
                  <div class="modal-header">
                      <button class="close" @click="hideModal()" type="button">&times;</button>
                      <div class="modal-title">
                          <p>发布房源</p>
                      </div>
                  </div>
                  <div class="modal-body">
                      <form class="form-horizontal" role="form">
                          <div class="form-group">
                              <label for="title" class="col-sm-2 control-label">房屋描述</label>
                              <div class="col-sm-10">
                                  <input v-model="new_entry.housedesc" id="title" type="text" class="form-control">
                              </div>
                          </div>
                          <div class="form-group">
                              <label for="qifei" class="col-sm-2 control-label">户型</label>
                              <div class="col-sm-10">
                                  <select id="qifei" class="form-control" v-model="new_entry.typeid">
                                      <option value="0">请选择房屋户型</option>
                                      <option v-for="item in categoryList.data" :value="item.typeid">{{item.typename}}</option>
                                  </select>
                              </div>
                          </div>

                          <div class="form-group">
                              <label for="createdate" class="col-sm-2 control-label">租金</label>
                              <div class="col-sm-10">
                                  <input v-model="new_entry.monthrent" id="createdate" type="text" class="form-control" >
                              </div>
                          </div>

                      </form>
                  </div>
                  <div class="modal-footer">
                      <button class="btn btn-default" @click="hideModal()">关闭</button>
                      <button class="btn btn-primary" @click="saveBook">添加</button>
                  </div>
              </div>
          </div>
      </div>

  </div>
</body>

  <script type="text/javascript">
          var vm=new Vue({
              el:"#vuebox",
              data:{
                  entries:{},
                  categoryList:{},
                  new_entry:{
                      housedesc:"",typeid:"0",monthrent:""
                  },
                  addHouseas:""
              },
              methods:{
                  selectEntry:function (i) {
                      axios.get("http://localhost:8081/selectHouseInfo",{params:{pageNum:i}}).then(res=>{
                          this.entries=res.data;
                      })
                  },
                  addHouse:function () {
                      $("#mymodal").modal('show');

                  },
                  saveBook:function () {
                      axios.post("http://localhost:8081/insetHouseInfo",this.new_entry).then(res=>{
                          this.addHouseas=res.data;
                          alert(this.addHouseas.msg);
                      })
                      this.hideModal();
                  },
                  hideModal:function () {
                      $("#mymodal").modal('hide')
                  },
              },
              mounted(){
                  axios.get("http://localhost:8081/seleHousetype").then(res=>{
                      this.categoryList=res.data;
                  })
                  this.selectEntry(1);
              }
      })
  </script>
</html>